package com.example.crm.servlet;

import com.example.crm.service.ICustomerService;
import com.example.crm.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/customer/remove")
public class CustomerRemoveServlet extends HttpServlet
{
    ICustomerService customerService = new CustomerServiceImpl();



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 1.
        String idStr = req.getParameter("id");
        int id = Integer.parseInt(idStr);

        // 2.
        customerService.removeById(id);

        // 3.
        resp.sendRedirect("/customer/list");
    }
}
